import React from 'react';
import { BackHandler } from 'react-native';

const AndroidBackButton = ({ onBack }) => {
  React.useEffect(() => {
    const backAction = () => {
      onBack();
      return true;
    };

    const backHandler = BackHandler.addEventListener('hardwareBackPress', backAction);

    return () => backHandler.remove();
  }, []);

  return null;
};

export default AndroidBackButton;